﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Newtonsoft.Json;
using System.IO;
using System.ComponentModel;

namespace TA.Turbo.Controls
{
	/// <summary>
	/// Summary description for BaseComplexControl
	/// </summary>
	public abstract class BaseComplexControl : BaseControl
	{
		#region PUBLIC
		public BaseComplexControl()
		{
			Tag = HtmlTextWriterTag.Div;
			_initControl = new ClientEvent(this, "Init");
		}
		#region PROPS
		[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
		public ClientEvent InitControl { get { return _initControl; } }
		#endregion
		#endregion
		#region INTERNAL
		#region VARS
		ClientEvent _initControl;
		#endregion
		#region PROPS
		#endregion
		#region METHODS
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);

			TurboPage.Current.Includes.Add(new ScriptResourceInclude { Resource = "TA.Turbo.Resources.JS.BaseComplexControl.js", TypeName = "TA.Turbo.TurboPage" });
		}
		protected override void Render(HtmlTextWriter writer)
		{
			base.Render(writer);

			RenderInitScript(writer);
		}
		protected virtual void RenderInitScript(HtmlTextWriter writer)
		{
			writer.AddAttribute(HtmlTextWriterAttribute.Type, "text/javascript");
			writer.RenderBeginTag(HtmlTextWriterTag.Script);

			RenderInitScriptInternal(writer);

			string script = InitControl.GetEventScript(ClientID);
			if (!string.IsNullOrEmpty(script))
				writer.Write(script);

			writer.RenderEndTag();
		}
		protected virtual void RenderInitScriptInternal(HtmlTextWriter writer)
		{

		}
		#endregion
		#endregion
	}
}